#!/bin/sh

# Copyright 2008  Robby Workman  Northport, AL, USA
# All rights reserved.
#
# Redistribution and use of this script, with or without modification, is
# permitted provided that the following conditions are met:
#
# 1. Redistributions of this script must retain the above copyright
#    notice, this list of conditions and the following disclaimer.
#
# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ''AS IS'' AND ANY EXPRESS OR IMPLIED
# WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
# MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
# EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
# OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

PRGNAM=wicd
VERSION=${VERSION:-1.4.2}
ARCH=noarch
BUILD=${BUILD:-1}
TAG=${TAG:-_SBo}

CWD=$(pwd)
TMP=${TMP:-/tmp/SBo}
PKG=$TMP/package-$PRGNAM
OUTPUT=${OUTPUT:-/tmp}

set -e

rm -rf $PKG
mkdir -p $TMP $PKG $OUTPUT
cd $PKG	# Yes, we'll do this all inside $PKG :)
rm -rf $PRGNAM-$VERSION
tar xvf $CWD/${PRGNAM}_${VERSION}-src.tar.bz2
chown -R root:root .
find . -type f -exec chmod 0644 {} \;
find . -type f -name "*.py" -exec chmod 0755 {} \;

# Unapplied patches - use them at your own risk.
# Thanks to nawcom for the ideas on this
#patch -p1 < $CWD/dhcpcd_daemon.py.diff
#patch -p1 < $CWD/dhcpcd_networking.py.diff

# Move the init script to Slackware's place and name it accordingly
# Also, let's not clobber it on upgrades
mkdir -p etc/rc.d
mv etc/init.d/wicd etc/rc.d/rc.wicd.new
chmod 0755 etc/rc.d/rc.wicd.new
rmdir etc/init.d

# Don't clobber the config file either
mv etc/dbus-1/system.d/wicd.conf etc/dbus-1/system.d/wicd.conf.new

# Give the menu entry desktop file a sane name (really doesn't matter though)
mv usr/share/applications/hammer-00186ddbac.desktop \
  usr/share/applications/wicd.desktop

# We don't have pm-utils on Slackware, so this can go
rm -rf etc/acpi

mkdir -p usr/doc/$PRGNAM-$VERSION
cat $CWD/README > usr/doc/$PRGNAM-$VERSION/README
# The source code does not include a copy of the the gpl-2.0
# license so lets add it for them.
zcat $CWD/gpl-2.0.txt.gz > usr/doc/$PRGNAM-$VERSION/LICENSE

mkdir -p install
cat $CWD/slack-desc > install/slack-desc
cat $CWD/doinst.sh > install/doinst.sh

/sbin/makepkg -l y -c n $OUTPUT/$PRGNAM-$VERSION-$ARCH-$BUILD$TAG.tgz
